home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Texteditors / Origami / Sources / src / keybind / tok2kbd.awk < prev   
Encoding:
AWK Script  |  1996-09-27  |  3.7 KB  |  114 lines

  1. BEGIN {
  2. # Sorry, but most awk's are not able to deal with double quotes...
  3.   doublequote=sprintf("%c",34);
  4.   #{{{}}}
  5. #  {{{  specify filenames
  6.   tokout="ocltoken.h"
  7.   keyout="autotoken.h"
  8. #  }}}
  9. #  {{{  print auto-gen-marks
  10.   print("/* This file is generated automatically by awk -f tok2kbd_source.awk */\n/* containing list with internal/external name pairs for OCL */") >keyout
  11.   print("/* This file is generated automatically by awk -f tok2kbd_source.awk */\n/* containing automatically genereted OCL token (keybind) */") >tokout
  12. #  }}}
  13. #  {{{  init fixed cmd arg range
  14.   cmd_range=8
  15. #  }}}
  16. }
  17. #{{{  set fixed cmd arg range
  18. /^#define +FIXED_COMMAND_RANGE/ {
  19.   cmd_range=$3
  20. }
  21. #}}}
  22. #{{{  comments start with #, so skip
  23. $0~/^#/ { next }
  24. #}}}
  25. #{{{  OCL-KEY
  26. $3=="OCL-KEY" {
  27. #   {{{  print to token list
  28.    print("   "$1",") >tokout
  29. #   }}}
  30. #   {{{  store name for key
  31.    keys["{ "doublequote $2 doublequote", "doublequote $1 doublequote" }"]=1
  32.    if ($4!="")
  33.       keys["{ "doublequote $4 doublequote", "doublequote $1 doublequote" }"]=1
  34. #   }}}
  35. }
  36. #}}}
  37. #{{{  OPP-KEY, add preprocessor name
  38. $3=="OPP-KEY" {
  39.   opps["{ "doublequote $2 doublequote", "doublequote $1 doublequote" }"]=1
  40.   if ($4!="")
  41.      opps["{ "doublequote $4 doublequote", "doublequote $1 doublequote" }"]=1
  42. }
  43. #}}}
  44. #{{{  set types for command and fixed command
  45. $3=="COM" || $3=="COM_I" || $3=="COM_II" || $3=="COM_P" || $3=="COM_IP" || $3=="COM_IIP" || $3=="COM_C" { typ=$3;fix_typ="" }
  46. $3=="COM_A" { typ="COM_A";fix_typ="COM" }
  47. $3=="COM_ID" { typ="COM_II";fix_typ="COM_I" }
  48. $3=="COM_D" { typ="COM_I";fix_typ="COM" }
  49. #}}}
  50. #{{{  not OCL-KEY or OPP-KEY, handle origami function token
  51. $3!="OCL-KEY" && $3!="OPP-KEY" {
  52.   if (fix_typ!="") {
  53.      for (i=cmd_range;i>0;i--) {
  54. #       {{{  store assembler name
  55.        asms["{ "doublequote $1"_M"i doublequote", "doublequote $1"_M"i doublequote" }"]=1
  56. #       }}}
  57. #       {{{  maybe store command name
  58.        if ($4!="NONE")
  59.           funs["{ "doublequote $1"_M"i doublequote", "doublequote $1"_M"i doublequote" }"]=1
  60. #       }}}
  61.      }
  62.      for (i=0;i<=cmd_range;i++) {
  63. #       {{{  store assembler name
  64.        asms["{ "doublequote $1"_"i doublequote", "doublequote $1"_"i doublequote" }"]=1
  65. #       }}}
  66. #       {{{  maybe store command name
  67.        if ($4!="NONE")
  68.           funs["{ "doublequote $1"_"i doublequote", "doublequote $1"_"i doublequote" }"]=1
  69. #       }}}
  70.      }
  71.   }
  72. #  {{{  store assembler name
  73.   asms["{ "doublequote $1 doublequote", "doublequote $1 doublequote" }"]=1
  74. #  }}}
  75. #  {{{  maybe store command name
  76.   if ($4!="NONE")
  77.      funs["{ "doublequote $4 doublequote", "doublequote $1 doublequote" }"]=1
  78. #  }}}
  79. }
  80. #}}}
  81. END {
  82. #  {{{  end token definition
  83.   print("#  ifdef OS_TOKEN") >tokout
  84.   print("      OS_TOKEN") >tokout
  85.   print("#  endif") >tokout
  86. #  }}}
  87. #  {{{  end name lists
  88. #  {{{  opps
  89.   print("name_code singles[]=\n {")>keyout
  90.   for ( i in opps )
  91.      print("   "i",") >keyout
  92.   print("   { 0,0 }\n };") >keyout
  93. #  }}}
  94. #  {{{  funs
  95.   print("name_code binding_names[]=\n {") >keyout
  96.   for ( i in funs )
  97.      print("   "i",") >keyout
  98.   print("   { "doublequote"no-operation"doublequote", "doublequote"O_NOP"doublequote" },\n   { 0,0 }\n };") >keyout
  99. #  }}}
  100. #  {{{  keys
  101.   print("name_code keytab_names[]=\n {") >keyout
  102.   for (i in keys )
  103.      print("   "i",") >keyout
  104.   print("   { FILE_STANDARD "doublequote"F"doublequote", "doublequote"INCLUDE"doublequote" },\n#  ifdef OS_KB_NAMES\n      OS_KB_NAMES\n#  endif\n   { 0, "doublequote"ERROR"doublequote" },\n };") >keyout
  105. #  }}}
  106. #  {{{  asms
  107.   print("name_code asm_token_names[]=\n {") >keyout
  108.   for ( i in asms )
  109.      print("   "i",") >keyout
  110.   print("   { "doublequote"O_NOP"doublequote", "doublequote"O_NOP"doublequote" },\n   { 0,0 }\n };") >keyout
  111. #  }}}
  112. #  }}}
  113. }
  114.